package com.chunyu.ask.controller.channel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.chunyu.ask.bean.Channel;
import com.chunyu.ask.controller.BaseController;
import com.chunyu.ask.service.ChannelService;
import com.chunyu.ask.util.PageUtils;

/**
 * 描        述：频道Controller
 * 创建时间：2016-8-18
 * @author Jibaole
 */
@Controller
@RequestMapping("/channel")
public class ChannelController extends BaseController{
	@Autowired
	private ChannelService channelService;
	
	   @RequestMapping("/{channelStr}/")
		public @ResponseBody ModelAndView getList(@PathVariable String channelStr) {
		 ModelAndView view = new ModelAndView("neirong");
		 Map<String,Object> paramMap = new HashMap<String,Object>();
		 paramMap.put("strId", channelStr);
		 paramMap.put("parentId", PageUtils.CHANNEL_ID_JKZXPD);
		 Channel channelObj =  channelService.getChannel(paramMap);
		 int id = 0;
		 if(channelObj != null){
			 id = channelObj.getId(); 
			 //tag标题
			 view.addObject("tagName",channelObj.getName());
			 view.addObject("abstName",channelObj.getAbst());
		 }
		 //频道分类
		 paramMap.clear();
		 paramMap.put("parentId", id);
		 paramMap.put("maxResult", PageUtils.MAX_PAGE);
		 List<Channel> channelSortList =  channelService.getList(paramMap);
		 view.addObject("channelSortList",channelSortList);
		 
		 //最新推荐
		 paramMap.clear();
		 paramMap.put("maxResult", 5);
			return view;
	 }
	 
	 @RequestMapping("/getById")
		public ModelAndView  getById(int id) {
		 ModelAndView view = new ModelAndView("neirong");
		 Channel channel= channelService.getById(id);
		 view.addObject("channel", channel);
		return view;
	 }
	 
}
